package com.qmyx.supply.admin.controller;

import com.ytjj.qmyx.supplychain.common.api.CommonResult;
import com.ytjj.qmyx.supplychain.mapper.entity.YxBankerStoreAddress;
import com.ytjj.qmyx.supplychain.service.BankerStoreAddressService;
import com.ytjj.qmyx.supplychain.service.ProvincesService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.*;

@RestController
@RequestMapping("/BankerReturn")
public class BankerReturnController {

    @Autowired
    private BankerStoreAddressService bankerStoreAddressService;
    @Autowired
    private ProvincesService provincesService;

    /**
     * 新增地址
     */
    @PostMapping("/insertAddress")
    public CommonResult insertAll(@RequestBody YxBankerStoreAddress yxBankerStoreAddress) {
        return CommonResult.success(bankerStoreAddressService.insertAll(yxBankerStoreAddress));
    }

    /**
     * 查询
     */
    @GetMapping("/selectAddress")
    public CommonResult selectAll(@RequestParam(required = false) Integer bankerId) {
        return CommonResult.success(bankerStoreAddressService.selectAll(bankerId));
    }

    /**
     * 查询
     */
    @GetMapping("/select")
    public CommonResult selectAll(@RequestParam(required = false) Integer pageNum,
                                  @RequestParam(required = false) Integer pageSize) {
        return CommonResult.success(bankerStoreAddressService.select(pageNum, pageSize));
    }

    /**
     * 修改
     */
    @PostMapping("/updateAddress")
    public CommonResult updateAll(@RequestBody YxBankerStoreAddress yxBankerStoreAddress) {
        return CommonResult.success(bankerStoreAddressService.updateById(yxBankerStoreAddress));
    }

    /**
     * 删除
     */
    @GetMapping("/deleteAddress")
    public CommonResult deleteAll(@RequestParam Integer id) {
        return CommonResult.success(bankerStoreAddressService.deleteAll(id));
    }

    /**
     * 修改默认地址
     */
    @GetMapping("/updateDefaultAddress")
    public CommonResult updateDefaultAddress(@RequestParam Integer id,@RequestParam Byte defaultFlag) {
        return CommonResult.success(bankerStoreAddressService.updateDefaultAddress(id,defaultFlag));
    }


    //获取省份
    @GetMapping("/getProvince")
    public CommonResult getProvince(@RequestParam(value="id",required=false) Integer id) {
       return CommonResult.success(provincesService.getProvince(id));
    }

    //根据省份id
    @GetMapping("/getCity")
    public CommonResult getCity(@RequestParam(value="id",required=false) Integer id) {
        return CommonResult.success(provincesService.getCity(id));
    }


    //根据省份id集
    @GetMapping("/getCitysBypids")
    public CommonResult getCitysBypids(@RequestParam(value="pids",required=false) String pids) {
        return CommonResult.success(provincesService.getCitysBypids(pids));
    }

    //根据城市id
    @GetMapping("/getArea")
    public CommonResult getArea(@RequestParam(value="id",required=false) Integer id) {
        return CommonResult.success(provincesService.getArea(id));
    }
}
